//
//  EmoticonPackages.swift
//  EmojiKeyboard
//
//  Created by ZhangZiang on 15/12/28.
//  Copyright © 2015年 ZhangZiang. All rights reserved.
//

import UIKit

class EmoticonPackages: NSObject {

    var id : String?
    var group_name_cn : String?
    
    lazy var emoticon = [Emoticon]()
    
    init(id : String, group_name_cn : String, emoticons : [[String : String]]) {
        super.init()
        
        self.id = id
        self.group_name_cn = group_name_cn
        
        //最后一个是删除
        var index = 0
        
        for item in emoticons {
        
           let e = Emoticon(dict: item)
            
            e.id = id
            
            emoticon.append(e)
            
            index++
            
            if index == 20 {
                let deleteE = Emoticon(isDelete: true)
                
                emoticon.append(deleteE)
                
                index = 0
            }
        }
        
        loadEmptyEmoticon()
    }
    
    private func loadEmptyEmoticon() {
        let delta = emoticon.count%21
        
        //正好被21整除则不需要空表情
        if delta == 0 {
            return
        }
        //最后不够的都填上空表情
        for _ in delta..<20 {
            let e = Emoticon(isEmpty: true)
            emoticon.append(e)
        }
        //最后一个用删除表情
        emoticon.append(Emoticon(isDelete: true))
    }
}
